﻿using Infragistics.Win.AppStyling;
using Infragistics.Win.UltraMessageBox;
using OrBitDataModule;
using OrBitDataModule.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrBitDataAcquisition.Dialog
{
    public partial class WebApiSetting : Form
    {
        public WebApiSetting()
        {
            InitializeComponent();
            this.ultraTextEditor_uri.KeyPress += UltraTextEditor_uri_KeyPress;
            this.ultraTextEditor_uri.Text = ConfigHelper.GetValue("BaseApiUri");
        }

        private void UltraTextEditor_uri_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                ultraButton_save_Click(null, null);
            }
        }

        private void ultraButton_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(ultraTextEditor_uri.Text))
            {
                UltraMessageBoxManager.Show(this, "地址不能为空！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Regex.IsMatch(ultraTextEditor_uri.Text, @"[a-zA-z]+://[^\s""<>]*"))
            {
                ConfigHelper.SetValue("BaseApiUri", ultraTextEditor_uri.Text);
                this.Close();
            }
            else
            {
                UltraMessageBoxManager.Show(this, "地址不符合规范！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
